--- title: "L1-058 6翻了" created: 2025-11-28 tags: - 算法 --- # L1-058 6翻了 ## 题目 [L1-058 6翻了](https://pintia.cn/problem-sets/994805046380707840/exam/problems/type/7?problemSetProblemId=1111914599408664577&page=0) ![[image-03239208.png]] ## 思路分析 ![[image-98d75182.png]] ## 代码实现 ```cpp #include using namespace std; #define endl '\n' using ll = long long; using ull = unsigned long long; using PII = pair; using Pll = pair; int dx[4]= {-1,0,1,0},dy[4]= {0,1,0,-1}; const int inf = 0x3f3f3f3f; int main() { ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); string s; getline(cin,s); string result; int i=0; while (i < s.size()) { if(s[i]=='6') { int j = i; while (j < s.size() && s[j] == '6') j++; int len = j - i; if (len > 9) { result += "27"; } else if (len > 3) { result += "9"; } else { result += string(len, '6'); } i = j; } else { result += s[i]; i++; } } cout << result << '\n'; return 0; } ``` ## 同类题型 ## 视频讲解 --- ⬅️ [[L1-057 PTA使我精神焕发|L1-057 PTA使我精神焕发]] 🏠 [[00-天梯赛]] ➡️ [[L1-059 敲笨钟|L1-059 敲笨钟]]